package Experiment1;

import edu.princeton.cs.algs4.StdStats;

import java.util.Scanner;

//计算运行时间，以微秒为单位
public class CostExperiment {
    
    private int nArray[];

    public CostExperiment(int nArray[]){
        this.nArray=nArray;
        PrintTable();
    }

    public void TakingExperiment(String algorithms_type){
        long result_array[]=new long[nArray.length];
        System.out.print(algorithms_type);
        for(int i=0;i<nArray.length;i++){
            long start_time,end_time;
            start_time=System.nanoTime();
            PercolationStats ex=new PercolationStats(nArray[i], 1,algorithms_type);
            end_time=System.nanoTime();
            result_array[i]=(end_time-start_time)/1000;
            System.out.print("\t"+result_array[i]);
        }
        System.out.println();

    }

    private void PrintTable(){
        System.out.print("Algorithms");
        for (int n : nArray) {
            System.out.print("\t"+n);
        }
        System.out.println();
    }
    
    public static void main(String[] args) {
        int arr[]={2,4,8,16,32,64,128,256,512,1024};
        
        CostExperiment ex=new CostExperiment(arr);
        ex.TakingExperiment("QuickFind");
        ex.TakingExperiment("WeightedQuickFind");
    }
}
